package org.bangumibuddy.mock.httpserver;

import com.sun.net.httpserver.HttpServer;
import lombok.SneakyThrows;
import org.bangumibuddy.mock.httpserver.handler.RSSHandler;
import org.bangumibuddy.mock.httpserver.handler.TorrentHandler;

import java.net.BindException;
import java.net.InetSocketAddress;

public class MockHttpServer {
    @SneakyThrows
    public void start(){
        try {
            HttpServer httpServer = HttpServer.create(new InetSocketAddress(4444),0);
            httpServer.createContext("/rss", new RSSHandler());
            httpServer.createContext("/torrents",new TorrentHandler());
            httpServer.start();
        }catch (BindException e)
        {
            //all ready started
        }
    }
}
